package view;

import javax.swing.table.AbstractTableModel;



@SuppressWarnings("serial")
class PlotTableModel extends AbstractTableModel {
	
	private boolean DEBUG = false;
	private Object[][] data;
    private String[] columnNames = {"ShowLap",
    								"Lap",
                                    "Time",
                                    "Top speed (Km/h) ",
                                    "Average speed (Km/h)",
                                    "Minimum speed (km/h)",
                                    "Length (m)",
                                    "Color"};
  
    public PlotTableModel(Object[][] matriu){
    	data = matriu;	  	
    }
    
    public int getColumnCount() {
        return columnNames.length;
    }

    public int getRowCount() {
        return data.length;
    }

    public String getColumnName(int col) {
        return columnNames[col];
    }

    public Object getValueAt(int row, int col) {
        return data[row][col];
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
	public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    public boolean isCellEditable(int row, int col) {
    	if(col == 0){
            return true;
        }else{
            return false;
        }
    }
 
    public void setValueAt(Object value, int row, int col) {
        if (DEBUG) {
            System.out.println("Setting value at " + row + "," + col
                               + " to " + value
                               + " (an instance of "
                               + value.getClass() + ")");
        }

        data[row][col] = value;
        fireTableCellUpdated(row, col);

        if (DEBUG) {
            System.out.println("New value of data:");
            printDebugData();
        }
    }

    private void printDebugData() {
        int numRows = getRowCount();
        int numCols = getColumnCount();

        for (int i=0; i < numRows; i++) {
            System.out.print("    row " + i + ":");
            for (int j=0; j < numCols; j++) {
                System.out.print("  " + data[i][j]);
            }
            System.out.println();
        }
        System.out.println("--------------------------");
    }

	/**
	 * @param data the data to set
	 */
	public void setData(Object[][] data) {
		this.data = data;
	}
}
